package com.gaotu.ci.news;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
public class BadService {
    @Autowired
    private NewsRepository newsRepository;
    public News getNewsById(Long id){
        News news = this.newsRepository.getById(id);
        log.info("load by id " + id +" , data is " + news);
        return news;
    }
    @Transactional(readOnly = false)
    public void createNews(String title, String content){
        News news = News.apply(title, content);
        try {
            this.newsRepository.save(news);
        }catch (Exception e){
            throw new RuntimeException();
        }
    }
}
